
#ifndef PREVIEWWINDOW_H
#define PREVIEWWINDOW_H

#include "wx/scrolwin.h"
#include "wx/bitmap.h"
#include "wx/image.h"
#include "FontDefinition.h"

#include "ft2build.h"
#include FT_FREETYPE_H

class PreviewWindow : public wxScrolledWindow
{
public:
    PreviewWindow( wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxHSCROLL | wxVSCROLL, const wxString& name = wxT( "scrolledWindow" ) );
    ~PreviewWindow(void);

    /** Update the preview display */
    void UpdateDisplay( const FontDefinition& fontDef );

    /** Save the image as a PNG file */
    void SavePNG( const StringUtil::String& fileName ) const;

    /** Set the display grid flag */
    void SetDisplayGrid( bool flag );
    /** Get the display grid flag */
    bool GetDisplayGrid() const;
    /** Set the display widths flag */
    void SetDisplayWidths( bool flag );
    /** Get the display widths flag */
    bool GetDisplayWidths() const;

    /** @typedef WidthsArrayType
        Defines an array of integers, used to store the widths of glyphs.
    */
    typedef std::vector< size_t > WidthsArrayType;

    /** Get the widths array */
    void GetGlyphWidths( WidthsArrayType* widths ) const;

protected:
	//void OnEraseBackground( wxEraseEvent& event );
	void OnPaint( wxPaintEvent& event );

    DECLARE_EVENT_TABLE()

private:
    wxBitmap    mCanvas;
    //wxBitmap    mPreviewImage;
    wxImage     mPreviewImage;
    wxBitmap    mGridOverlay;
    wxBitmap    mWidthsOverlay;
    bool        mDisplayGrid;
    bool        mDisplayWidths;
    WidthsArrayType mGlyphWidths;

    /** Render a glyph to the display bitmap (mPreviewImage) */
    void RenderGlyph( FT_Bitmap* bitmap, size_t x, size_t y );
    /** Render an aliased glyph to the display bitmap (mPreviewImage) */
    void RenderGlyphAliased( FT_Bitmap* bitmap, size_t x, size_t y );
};

#endif  // PREVIEWWINDOW_H
